package com.example.ioc.factorybean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.Configuration;

/**
 * Description
 *
 * @author tcwong
 * @date 2022/7/24
 * Since 1.8
 */
@Configuration
public class SoaServiceConfig implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
       DefaultListableBeanFactory beanFactory =  (DefaultListableBeanFactory)configurableListableBeanFactory;

        BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(SoaServiceFactory.class);
        builder.addPropertyValue("clazz",DefaultSoaService.class);
        beanFactory.registerBeanDefinition(DefaultSoaService.class.getSimpleName()+"-proxy",builder.getBeanDefinition());

    }
}
